classes.maps.TiledHallway = cc.TMXTiledMap.extend({
    ctor: function() {
        this._super();
        this.initWithTMXFile('res/hall.tmx');
        this.initObstacles();
    },
     getTileCoordForPosition : function(position) {
        var x = Math.floor(position.x / this.getTileSize().width);
        var y = Math.floor(((this.getTileSize().height * this
                .getMapSize().height) - position.y) / this.getTileSize().height);
        return new cc.Point(x, y);
    },

    isCollidable : function(tileCoord) {
        var collidableLayer = this.getLayer("collidable");
        var gid = collidableLayer.getTileGIDAt(tileCoord);
        if (gid) {
            var tileProperties = this.propertiesForGID(gid);
            return true;
        }
        return false;
    },
    initObstacles: function() {
        this.obstacles = [];
        var mapWidth = this.getMapSize().width,
        mapHeight = this.getMapSize().height,
        tileWidth = this.getTileSize().width,
        tileHeight = this.getTileSize().height;
        var collidableLayer = this.getLayer("collidable");
        var i,j;
        var rect = null;
        for (j=0; j<mapHeight; j++) {
            for (i=0; i<mapWidth;i++) {
                var tileCoord = new cc.Point(i,j);
                var gid = collidableLayer.getTileGIDAt(tileCoord);
                if(gid) {
                    if(!rect) {
                        rect = cc.rect((i+1)*tileWidth, (mapHeight-(j+1))*tileHeight, tileWidth, tileHeight);
                    } else {
                        rect = cc.rect(rect.x, rect.y, rect.width+tileWidth, rect.height);
                    }
                } else {
                    if(rect) {
                        this.obstacles.push(rect);
                        rect = null;
                    }
                }
            }
            if(rect) {
                this.obstacles.push(rect);
                rect = null;
            }
        }
    }
});
//var tiledMap = new classes.maps.TiledHallway();